/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.pharmproject.conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author rodrigo
 */
public class Conexao {
    
    
    private static Connection con = null;
    private static Conexao instance = null;
    
    public Connection getConector() throws ClassNotFoundException, SQLException {
        
        if(con == null){
            
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/mypharm", "root","root");
            
        }
        
        return con;
    }
    
    public static synchronized Conexao getInstance(){
        if (instance == null) {
            return new Conexao();
        } else {
            return instance;
        }
    }

    @Override
    protected void finalize() throws Throwable {
        if (instance != null){
            
        }  
    }
    
    public void closeConnection(){
        
        try {
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
